package com.yikome.schedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.yikome.config.ServerConfig;
import com.yikome.delivery.service.DeliveryService;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class GenerateDeliverySchedule {

	@Autowired
	private ServerConfig serverConfig; 
	
	@Autowired
	private DeliveryService deliveryService;
	
	@Scheduled(cron = "${schedule.delivery.generate}")
	public void generateDeliveryJob() throws Exception {
		
		String hostAddressAndPort = serverConfig.getHost() + "-" + serverConfig.getServerPort();
		
		log.info("{} [ip]:{} {} [methods]:{} {}" , DateUtil.now() , hostAddressAndPort , "GenerateDeliverySchedule" , "generateDelivery" , "start");
		
		deliveryService.generateDelivery();
		
		log.info("{} [ip]:{} {} [methods]:{} {}" , DateUtil.now() , hostAddressAndPort , "GenerateDeliverySchedule" , "generateDelivery" , "end");
	}
}
